package com.cloud.feign.controller;

import com.cloud.feign.client.IFeignClient;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class HelloController {


    @Value("${server.port}")
    String port;

    @Autowired
    private IFeignClient iFeignClient;

    @GetMapping("test")
    @HystrixCommand(fallbackMethod = "fallback")
    public String test(@RequestParam("name") String name){
//        try {
//            Thread.sleep(7000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        return iFeignClient.hello(name);
    }

    public String fallback(String name){
       return "Controller里的降级方法";
    }

    @GetMapping("consumer")
    public String consumer(){
        return "service from feign-consumer";
    }
}
